<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>密钥充值</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
</head>
<style>
    .layui-form-label{
        width: 90px;
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15>
                    <div class="layui-form" lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">输入充值金额</label>
                            <div class="layui-input-inline">
                                <input type="text" name="depid" id="depid" placeholder="请输入充值金额" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" id="qr" lay-filter="formDemo">确认</button>
                                <button class="layui-btn layui-icon layui-icon-close" id="back">
                                    取消
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    layui.use('table', function () {
        var $ = layui.$
        var table = layui.table
        var data = layui.data("stationdata2");
        //返回的监听事件
        $("#fanhui").click(function () {
            location = "stationMoney.html";
        })
        $("#qr").click(function () {
            var depid = $("#depid").val();
            var depid2 = /^([1-9][0-9]*){1,3}$/;
            if (!depid2.test(depid)) {
                layer.msg("格式错误", {icon: 2})
                return;
            }
            // 格式正m 确充值
            $.ajax({
                url: 'http://localhost:8080/admin/station-key-recharge/insertTerminalKey',
                type: "post",
                data: {
                    stationKeyRechargeSum: depid,
                    stationKeyRechargeAdmin: data.getdata.station_admin_id,
                    stationKeyRechargeStation: data.getdata.station_id
                },
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg("充值成功", {
                            icon: 1,
                            time: 500
                        });
                        setTimeout(function () {
                            // 格式正m 确充值
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);    //关闭弹出层
                            window.parent.location.reload();   //刷新父界面
                        }, 500);
                        return;
                    }
                    layer.msg("余额不足", {
                        icon: 2
                    })
                    return;
                },
                error: function (res) {//服务器异常
                    layer.msg("失败,服务器异常", {icon: 2});
                }
            })
        })

        $('#back').click(function () {
            var index = parent.layer.getFrameIndex(window.name) //获取窗口索引
            parent.layer.close(index)    //关闭弹出层
        })
    })
</script>
</html>